function Img2 = lightBalance( Img )
%LIGHTBALANCE vyvzi svetlo v leve a prave casti obrazku

[SizeY, SizeX] = size(Img);
L = sum(Img) / SizeX;
ImgE = edge(Img, 'sobel', 0.03);
ImgE(round(SizeY/2), round(SizeX/2)) = true; 
xc = M_pq(ImgE,1,0) / M_pq(ImgE,0,0); %odhad x-ove souradnice svisle osy
s = round(2 * xc - SizeX);
Lr = wrev(L);
if s > 0
    Lr = [repmat(Lr(1), 1, s) Lr(1:(SizeX - s))];
elseif s < 0
    s = -s;
    Lr = [Lr((1+s):SizeX) repmat(Lr(SizeX), 1, s)];
end
Q = sqrt((0.05+L) .\ (0.05+Lr));
Q = smooth(Q, 7, 'moving');
Img2 = Img * diag(Q);
Img2(Img2 > 1) = 1;
end

